package org.jeecg.modules.demo.zc.carCost.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.demo.zc.carCost.entity.CarCost;

import java.util.List;

@Mapper
public interface CarCostMapper extends BaseMapper<CarCost> {

    @Select("select ORG_ID from ORG_INFO where ORG_CODE=#{orgCode}")
    Integer getOrgId(String orgCode);

    @Select("select ORG_ID from ORG_INFO where PARENT_ORG_ID=#{orgId}")
    List<Integer> getparentOrgIds(Integer orgId);

//    @Select("SELECT PLATE_NUMBER AS plateNumber, MAX(ORG_ID) AS orgId, MAX(ORG_CODE) AS orgCode, MAX(ORG_NAME) AS orgName, COALESCE(SUM(PARKING_FEE),0) AS parkingFee, COALESCE(SUM(HIGH_SPEED_FEE),0) AS highSpeedFee, COALESCE(SUM(TOLL_FEE),0) AS tollFee, COALESCE(SUM(FUEL_FEE),0) AS fuelFee, COALESCE(SUM(CHARGING_FEE),0) AS chargingFee, COALESCE(SUM(OTHER_FEE),0) AS otherFee, COALESCE(SUM(REPORT_FEE),0) AS reportFee, COALESCE(SUM(INSURE_FEE),0) AS insureFee, COALESCE(SUM(REPAIR_FEE),0) AS repairFee, COALESCE(SUM(MAINTAIN_FEE),0) AS maintainFee, COALESCE(SUM(VIOLATION_AMOUNT),0) AS violationAmount, COALESCE(SUM(MOT_CHECK_FEE),0) AS motCheckFee, MAX(ORG_MGR_NAME) AS orgMgrName FROM CAR_COST where ORG_ID in(#{orgIdsStr}) GROUP BY PLATE_NUMBER")
    @Select("SELECT PLATE_NUMBER AS plateNumber, MAX(ORG_ID) AS orgId, MAX(ORG_CODE) AS orgCode, MAX(ORG_NAME) AS orgName, COALESCE(SUM(PARKING_FEE),0) AS parkingFee, COALESCE(SUM(HIGH_SPEED_FEE),0) AS highSpeedFee, COALESCE(SUM(TOLL_FEE),0) AS tollFee, COALESCE(SUM(FUEL_FEE),0) AS fuelFee, COALESCE(SUM(CHARGING_FEE),0) AS chargingFee, COALESCE(SUM(OTHER_FEE),0) AS otherFee, COALESCE(SUM(REPORT_FEE),0) AS reportFee, COALESCE(SUM(INSURE_FEE),0) AS insureFee, COALESCE(SUM(REPAIR_FEE),0) AS repairFee, COALESCE(SUM(MAINTAIN_FEE),0) AS maintainFee, COALESCE(SUM(VIOLATION_AMOUNT),0) AS violationAmount, COALESCE(SUM(MOT_CHECK_FEE),0) AS motCheckFee, MAX(ORG_MGR_NAME) AS orgMgrName FROM CAR_COST where ORG_ID in(${orgIdsStr}) GROUP BY PLATE_NUMBER")
    List<CarCost> getCostSum(Page<CarCost> page,String orgIdsStr);
}
